<!-- 搜索项目 -->
<template>
  <h-select-input-popup
    ref="hSelectInputPopup"
		:useSearch="false"
    v-model="val"
    v-bind="$attrs"
    v-on="$listeners"
    :params="queryParams"
    :keywords.sync="keywords"
    :getList="urlList"
		:recordList="redistributionDtList"
		:disabled="disabled"
		:isRequest="isRequest"
		:isrecordList = "true"
    @getDetail="getDetail"
		searchPlaceholder="请输入任务说明"
    @change="$emit('change', $event)"
  >
    <template v-slot:default="{ item }">
      <view class="project-item">
        <view class="option">
          <view class="lf">业务分类编码</view>
          <view class="rl">{{ item.categoryCode }}</view>
        </view>
        <view class="option">
          <view class="lf">业务分类名称</view>
          <view class="rl">{{ item.categoryName }}</view>
        </view>
        <view class="option">
          <view class="lf">合同占比(%)</view>
          <view class="rl">{{ (item.contractRate === '' ||  item.contractRate === null || item.contractRate === undefined)? '' : (Number(item.contractRate).toFixed(2) + '') }}</view>
        </view>
        <view class="option">
          <view class="lf">分配合同额(元)</view>
          <view class="rl">{{ item.contractAmount }}</view>
        </view>
        <view class="option">
          <view class="lf">生产团队</view>
          <view class="rl">{{ filterMultiDictText(dictOptions['productTeam'], item.productTeam + '') }}</view>
        </view>
        <view class="option">
          <view class="lf">团队负责人</view>
          <view class="rl">{{ filterMultiDictText(dictOptions['teamLeader'], item.teamLeader + '') }}</view>
        </view>
        <view class="option">
          <view class="lf">任务说明</view>
          <view class="rl">{{ item.taskDescription }}</view>
        </view>
      </view>
    </template>
  </h-select-input-popup>
</template>

<script>
import { relationTaskList } from '@/api/index.js'
import { relationTaskInfo } from '@/api/index.js'
import { filterMultiDictText, initDictOptions } from '@/utils/JDictSelectUtil.js'
export default {
  name: 'HSelectProjectInputPopup',
  data() {
    return {
			filterMultiDictText,
			initDictOptions,
			dictOptions: {},
      params: {
				column: 'createTime',
				order: 'desc',
        pageNo: 1,
        pageSize: 10,
      },
      keywords: '',
    }
  },
  model: {
    prop: 'value',
    event: 'input',
  },
  props: {
    value: {
      type: [String, Number, Array],
      default: null,
    },
    api: {
      type: Function,
      default: relationTaskList,
    },
		disabled: {
			type: Boolean,
			required: false,
			default: false,
		},
		open: {
			type: Boolean,
			required: false,
			default: false,
		},
		multi: {
			type: Boolean,
			default: false,
			required: false,
		},
		props: {
			type: Object,
			default: null,
		},
		projectId: {
			type: [Number, String],
			default: '',
		},
		// 第一次是否请求
		isRequest: {
		  type: Boolean,
		  default: true,
		},
		// 分配任务信息列表
		redistributionDtList: {
			type: [Array],
			default: () => []
		}
  },
  computed: {
    val: {
      get() {
        return this.value
      },
      set() {
        this.$emit('input', this.value)
      },
    },
		urlList () {
			return relationTaskList
		},
    queryParams() {
			const params = {
			  ...this.params,
			}
			if (this.keywords) {
			  params.taskDescription = '*' + this.keywords + '*'
			}
      if (this.projectId) {
        params.projectId = this.projectId
      }
      return params
    },
  },
	created() {
		this.initDictConfig()
	},
  methods: {
		async initDictConfig() {
			initDictOptions('erp_omc_team_manager,alias_name,id').then((res) => {
				if (res.success) {
					this.$set(this.dictOptions, 'productTeam', res.result)
				}
			})
			initDictOptions('erp_employee_file,name,id').then((res) => {
				if (res.success) {
					this.$set(this.dictOptions, 'teamLeader', res.result)
				}
			})
		},
    // 获取详情
    getDetail(value) {
      if (this.redistributionDtList && this.redistributionDtList.length > 0) {
        // 判断value是否等于recordList中的id
        this.redistributionDtList.forEach((item) => {
          if (item.id == value) {
            this.$refs.hSelectInputPopup.title = item.categoryName
            this.$emit('select', {
              data: item,
              id: value
            })
          }
        })
      }
    }
  },
}
</script>

<style lang="scss" scoped>
// 按钮
.btn {
  position: fixed;
  bottom: 20rpx;
  width: 95%;
}
</style>
